#include "FrogMonster.h"

FrogMonster::FrogMonster(int locx, int locy, int locz,vector<vector<vector<Floor*>>> floor)
{
	collision = false;
	dir = NODIR;
	theFloor = floor;
	x = locx;
	y = locy;
	z = locz;
	type = FROGMONSTER;
	counter = 0;

	removeable = false;
}

FrogMonster::~FrogMonster(void)
{
}



void FrogMonster::doTimeStep(Object *tait)
{
	counter++;
	if(counter ==5){
		counter = 0;
		if(tait->getX() == x){
			if(tait->getY() > y)
				move(DOWN);
			else if(tait->getY() < y)
				move(UP);
		}
		else if(tait->getY() == y){
			if(tait->getX() > x)
				move(RIGHT);
			else if(tait->getX() < x)
				move(LEFT);
		}
		else{
			int randomInt = rand()%2;
			if(randomInt==0){
				if(tait->getX() > x){
					move(RIGHT);
				}
				else if(tait->getX() < x){
					move(LEFT);
				}
				if(tait->getY() > y && collision){
					collision = false;
					move(DOWN);
				}
				else if(tait->getY() < y && collision){
					collision = false;
					move(UP);
				}
			}
			if(randomInt==1){
				if(tait->getY() > y){
					move(DOWN);
				}
				else if(tait->getY() < y){
					move(UP);
				}
				if(tait->getX() > x && collision){
					collision = false;
					move(RIGHT);
				}
				else if(tait->getX() < x && collision){
					collision = false;
					move(LEFT);
				}
			}
		}


	}

}

//When an this object is hit by the collider do certain stuff
void FrogMonster::collide(Object* collider)
{
	//assume that collision will be over (if its not it'll flag itself again)
	collision=false;


}

//When this object hits another object do certain stuff (ie if its an exit win the game)
void FrogMonster::collideWith(Object* collidee){
	//All collisions must end by flagging collision as false
	collision = false;
	if (collidee->getType() == TAIT) {
		collidee->move(dir);
	}
	
}

bool FrogMonster::legalFloor(){
	FloorType nextFloor;
	FloorState floorState;
	FloorType currentFloor = theFloor[x][y][z]->getType();
	if(bounds()){
		switch(dir){
		case UP:	
			nextFloor = theFloor[x][y-1][z]->getType();
			floorState = theFloor[x][y-1][z]->getFloorState();
			return  !(nextFloor == WSOUTH) && !(currentFloor == WNORTH) &&!(floorState == BLOCKCREATED) 
				&& !(nextFloor == GRAVEL) && !(nextFloor == WATER)&& !(nextFloor == FORCE)&& !(nextFloor == FIRE);
			break;
		case DOWN:	
			nextFloor = theFloor[x][y+1][z]->getType();
			floorState = theFloor[x][y+1][z]->getFloorState();
			return  !(nextFloor == WNORTH)&& !(currentFloor == WSOUTH)&&!(floorState == BLOCKCREATED)
				&& !(nextFloor == GRAVEL) && !(nextFloor == WATER)&& !(nextFloor == FORCE)&& !(nextFloor == FIRE);
			break;
		case RIGHT:	
			nextFloor = theFloor[x+1][y][z]->getType();
			floorState = theFloor[x+1][y][z]->getFloorState();
			return  !(nextFloor == WWEST)&& !(currentFloor == WEAST)&&!(floorState == BLOCKCREATED)
				&& !(nextFloor == GRAVEL) && !(nextFloor == WATER)&& !(nextFloor == FORCE)&& !(nextFloor == FIRE);
			break;
		case LEFT:	
			nextFloor = theFloor[x-1][y][z]->getType();
			floorState = theFloor[x-1][y][z]->getFloorState();
			return  !(nextFloor == WEAST)&& !(currentFloor == WWEST)&&!(floorState == BLOCKCREATED)
				&& !(nextFloor == GRAVEL) && !(nextFloor == WATER) && !(nextFloor == FORCE)&& !(nextFloor == FIRE);
			break;

		}
	}
	return false;
}

void FrogMonster::doFloor(Equip currentEquip){

	condition = FINE;
	//sliding will set you into sliding unless you're against a wall

}